"""
    Copyright 2008, M.B.I. srl.
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301, USA.
"""
 
from pyOsiCommon import *

Solvers = ['CBC','CLP','MSK','CPX']

def ChangeCoeffs(self,rows,cols,vals):
    if self.__changeCoeffs_implementation == None:
        raise RuntimeError, "pyOsi Solver instance hasn't got a specific changeCoeffs method"
    else:    
        return self.__changeCoeffs_implementation(self,rows,cols,vals)
        
    
OsiSolverInterface.changeCoeffs = ChangeCoeffs

def getOsi(solver = 'CBC'):
    try: 
        if solver == 'CBC': 
            import pyOsiCbc
            actualSolver = pyOsiCbc.getOsi()
            actualSolver.hasChangeCoeffs = False
            actualSolver.__changeCoeffs_implementation = None
            return actualSolver
        elif solver == 'CLP':
            import pyOsiClp
            actualSolver = pyOsiClp.getOsi()
            actualSolver.hasChangeCoeffs = False
            actualSolver.__changeCoeffs_implementation = None
            return actualSolver
        elif solver == 'MSK':
            import pyOsiMsk
            actualSolver = pyOsiMsk.getOsi()
            actualSolver.hasChangeCoeffs = True
            actualSolver.__changeCoeffs_implementation = pyOsiMsk.ChangeCoeffs
            return actualSolver
        elif solver == 'CPX':
            import pyOsiCpx
            actualSolver = pyOsiCpx.getOsi()
            actualSolver.hasChangeCoeffs = True
            actualSolver.__changeCoeffs_implementation = pyOsiCpx.ChangeCoeffs
            return actualSolver
        else:
            print "Unkonwn solver"
            return None

    except:
        print "The sfecified Solver is not available"
        return None

